package com.albaba.designpattern.flyweight.text_001;

/**
 * @Description: TODO
 * @Author zx
 * @Date 2025/2/21 17:01
 * @Version 1.0
 */
public class Client {
    public static void main(String[] args) {
        // 获取工厂对象
        FlyweightFactory flyweightFactory = new FlyweightFactory();

        // 通过工厂对象获取共享的享元对象
        Flyweight flyweight1 = flyweightFactory.getFlyweight("A");

        flyweight1.operation("a1ExState");

        Flyweight flyweight2 = flyweightFactory.getFlyweight("A");

        flyweight2.operation("a2ExState");

        System.out.println(flyweight1 == flyweight2);

        // 获取非共享的享元对象
        UnsharedFlyweight unsharedFlyweight1 = new UnsharedFlyweight("A");
        UnsharedFlyweight unsharedFlyweight2 = new UnsharedFlyweight("A");
        System.out.println(unsharedFlyweight1 == unsharedFlyweight2);


    }
}
